<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" 
		xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
		xmlns:gml="http://www.opengis.net/gml" 
		xmlns:ogr="http://ogr.maptools.org/"
		xmlns:="http://www.opengis.net/gml">

<xsl:output method="xml" indent="yes" />
<xsl:template match="/ogr:FeatureCollection">

	<xsl:for-each select='gml:featureMember/ogr:NUTS_RG_60M_2006' >
		<xsl:result-document href="{concat('id/',ogr:NUTS_ID,'_geometry.gml')}">
			<xsl:apply-templates select="ogr:geometryProperty/child::node()">
				<xsl:with-param name="nuts_id" select="ogr:NUTS_ID"/>
			</xsl:apply-templates>
		</xsl:result-document>
	</xsl:for-each>

</xsl:template>

<xsl:template match="gml:MultiPolygon|gml:MultiSurface|gml:Polygon|gml:Surface|gml:LineString|gml:Curve">
	<xsl:param name="nuts_id" />
	<xsl:copy>
		<gml:name><xsl:value-of select="$nuts_id"/></gml:name>
		<gml:metaDataProperty>
			<gml:GenericMetaData xmlns:dc="http://purl.org/dc/elements/1.1/">
				<ogr:NUTS_ID><xsl:value-of select="$nuts_id"/></ogr:NUTS_ID>
				<dc:rights>© EuroGeographics for the administrative boundaries.</dc:rights>
			</gml:GenericMetaData>
		</gml:metaDataProperty> 
		<xsl:copy-of select="child::node()"/>
	</xsl:copy>
</xsl:template>

</xsl:stylesheet>